interface IArmyObject {
    seq: string;
    operate(): void;
}
class Team implements IArmyObject {
    seq: string;
    private _soldires: IArmyObject[];
    operate(): void {
        console.log("Team ${this.seq} operates");
        this._soldires.map((soldier: IArmyObject) => {
            soldier.operate();
        });
    }
    addSoldier(newSoldier: IArmyObject): void {
        const soldier = this._soldires.filter((soldier: IArmyObject, index) => {
            return soldier.seq === newSoldier.seq;
        });
        if (soldier.length < 1) {
            console.log("new solier added ${soldier.seq} in team ${this.seq}");
            this._soldires.push(newSoldier);
        } else {
            console.log("soldier already in the team");
        }
    }
    soldierGone(deadSoldier: IArmyObject): void {
        const deads = this._soldires.map((soildier: IArmyObject, index) => {
            if (soildier.seq === deadSoldier.seq)
                return index;
        });

        if (deads.length > 0) {
             console.log("soldier dead in the fight ${deadSoldier.seq}");
             this._soldires.splice(deads[0],1);
        } else
        {
            console.log("no soldier dead");
        }
    }
    constructor(seq: string) {
        this.seq = seq;
        this._soldires = [];
    }
}
class Soldier implements IArmyObject
{
    operate(): void {
       console.log("Soldier action now ${this.seq}");
    }
    seq: string;
    constructor(seq:string)
    {
        this.seq = seq;
    }
  
}

export class CompositeAction
{
    test()
    {
        const team = new Team("soldier 6 stread team");
        const newBeeTeam = new Team("new bee soldier team");
        
        const soldierJoe = new Soldier("Joe");
        const soldierBilly = new Soldier("Billy");
        const soldierEmily = new Soldier("emily");

        team.addSoldier(soldierBilly);
        team.addSoldier(soldierEmily);
        team.addSoldier(soldierJoe);


        const oneSoldier = new Soldier("one");
        newBeeTeam.addSoldier(oneSoldier);

        team.operate();
        newBeeTeam.operate();
        team.soldierGone(soldierJoe);

        

    }
}